package tcards.android;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TextDisplay extends LinearLayout {
	private void init(AttributeSet attrs) {
		TypedArray tArray = getContext().obtainStyledAttributes(attrs, R.styleable.Field);
		
		String text = tArray.getString(R.styleable.Field_label);
        if (text != null) { 
        	getLabel().setText(text + ": ");
        }
              
        text = tArray.getString(R.styleable.Field_content);
        if (text != null) { 
        	getContent().setText(text);
        }
        
		tArray.recycle();
	}	
	
	public TextDisplay(Context context) {
		this(context, null, 0);
	}

	public TextDisplay(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public TextDisplay(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		LayoutInflater li = LayoutInflater.from(context);
		addView(li.inflate(R.layout.text_display, this, false));
		if (attrs != null) {
			init(attrs);
		}
	}

	public TextView getLabel() {
		return (TextView) findViewById(R.id.displayLabel);
	}
	
	public TextView getContent() {
		return (TextView) findViewById(R.id.displayContent);
	}
	
	public String getTextValue() {
		return getContent().getText().toString();
	}
	
	public void setTextValue(String value) {
		if (value == null) {
			value = "";
		}
		
		getContent().setText(value);
	}
}